﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;

namespace docTranslate
{
    public partial class rbbDocTranslate : OfficeRibbon
    {
        public rbbDocTranslate()
        {
            InitializeComponent();
        }

        private void Ribbon_Load(object sender, RibbonUIEventArgs e)
        {

        }

        private void btnTranslate_Click(object sender, RibbonControlEventArgs e)
        {
            if (!btnTranslate.Checked)
            {
                try
                {
                    Globals.ThisAddIn.CustomTaskPanes.Remove(Globals.ThisAddIn.TranslateCTP);
                }
                catch (Exception)
                {
                    Globals.ThisAddIn.TranslateCTP = Globals.ThisAddIn.CustomTaskPanes.Add(new UCTranslate(), "Translate");
                    Globals.ThisAddIn.TranslateCTP.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionFloating;
                    Globals.ThisAddIn.TranslateCTP.Height = 409;
                    Globals.ThisAddIn.TranslateCTP.Width = 348;
                    Globals.ThisAddIn.TranslateCTP.Visible = true;

                    Globals.ThisAddIn.TranslateCTP.VisibleChanged += new EventHandler(TranslateCTP_VisibleChanged);

                    btnTranslate.Checked = true;
                }
            }
            else
            {
                Globals.ThisAddIn.TranslateCTP = Globals.ThisAddIn.CustomTaskPanes.Add(new UCTranslate(), "Translate");
                Globals.ThisAddIn.TranslateCTP.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionFloating;
                Globals.ThisAddIn.TranslateCTP.Height = 409;
                Globals.ThisAddIn.TranslateCTP.Width = 348;
                Globals.ThisAddIn.TranslateCTP.Visible = true;

                Globals.ThisAddIn.TranslateCTP.VisibleChanged += new EventHandler(TranslateCTP_VisibleChanged);
            }
        }

        private void TranslateCTP_VisibleChanged(object sender, EventArgs e)
        {
            btnTranslate.Checked = Globals.ThisAddIn.TranslateCTP.Visible;
        }

    }
}
